<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>寒衣选择</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form" action="" id="product" lay-filter="component-form-group">
                <input type="hidden" name="id" th:value="${product.id}">
                <input type="hidden" name="appid" th:value="${app.id}">
                <div class="layui-form-item">
                    <label class="layui-form-label">款式</label>
                    <div class="layui-input-block">
                        <input readonly type="text" th:value="${product.name}" name="name" required class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">编码</label>
                    <div class="layui-input-block">
                        <input readonly type="text" th:value="${product.productNumber}" name="productNumber" required class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">规格</label>
                    <div id="skus" style="display: inline-flex;">
                        <div th:each="sku : ${product.skus}">
                            <input type="radio" name="sku" class="layui-input" th:value="${sku.id}" th:title="${sku.name}">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">图片</label>
                    <div id="imgs" style="display: inline-flex;">
                        <div th:each="img : ${product.images}">
                            <input type='hidden' name='imgs' th:value="${img.path}"/>
                            <img style='display: inherit' height='200px' th:src="${img.path}">
                        </div>
                    </div>


                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">尺码表</label>
                    <div class="layui-input-block">
                        <textarea readonly name="description" th:text="${product.description}" class="layui-textarea" id="description" style="display: none;">
                        </textarea>
                    </div>
                </div>

                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-input-block">
                        <div>
                            <button class="layui-btn" type="button">返回</button>
                            <button class="layui-btn" lay-submit="" lay-filter="app-save">提交</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>


<script src="/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'laydate', 'upload','layedit'], function () {
        var $ = layui.$
            , admin = layui.admin,
            layedit = layui.layedit
            , element = layui.element
            , layer = layui.layer
            , laydate = layui.laydate,
            upload = layui.upload
            , form = layui.form;
        //富文本编辑器配置图片上传接口，这个配置必须是在渲染之前
        //这个接口返回值必须严格匹配layui的标准
        layedit.set({	//设置图片接口
            uploadImage: {
                url: '/api/file/img', //接口url
                type: 'post'
            }
        });
        // 渲染富文本编辑器
        var index =  layedit.build('description', {
            tool: ['strong', 'italic', 'underline', 'del', '|', 'left', 'center', 'right', 'image','face', 'link', 'unlink'],
            height: 400

        });


        //绑定衣服提交
        form.on("submit(app-save)",function (obj) {

            console.info(obj.field)
            $.ajax({
                type: 'post',
                url: '/application/check-pro',
                data: {id: obj.field.appid,skuId: obj.field.sku,productId: obj.field.id},
                success: function (res) {
                    if(res.data){
                        layer.msg("选择成功",{icon: 6,time: 1500},function () {
                            //跳转到寒衣列表
                            window.location = "/application-apply"
                        })
                    }
                }
            })
            return false
        })
    });
</script>
</body>
</html>
